﻿using UnityEngine;
using System.Collections;

public class FadeIn : MonoBehaviour {

    private GameObject texture;
    private float count;
    private float amount;
    private bool isRun;

    public void createFade(float amount)
    {
        this.amount = amount;

        texture = CreateTexture.getInstance().getTexture("FadeIn", Color.black, 1);
        
        count = 1;
        isRun = true;
    }

    public bool existFade()
    {
        return !isRun;
    }

    void Update()
    {

        if (isRun)
        {
            count -= amount * Time.deltaTime;

            texture.guiTexture.color = new Color(0, 0, 0, count);

            if (count <= 0)
            {
                Destroy(texture);
                DestroyObject(this);
            }
        }
    }
}
